package com.artPreter.service.impl;


import com.artPreter.mapper.BottomLinkMapper;
import com.artPreter.pojo.BottomLink;
import com.artPreter.service.IBottomLinkService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

/**
 * <p>
 * 艺术分类表 服务实现类
 * </p>
 *
 * @author jarvis
 * @since 2025-01-02
 */
@Service
public class BottomLinkServiceImpl extends ServiceImpl<BottomLinkMapper, BottomLink> implements IBottomLinkService {

    @Override
    public List<BottomLink> getList(BottomLink bottomLink) {
        LambdaQueryWrapper<BottomLink> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BottomLink::getStatus,1);
        List<BottomLink> result= this.baseMapper.selectList(queryWrapper);
        return result;
    }

    @Override
    public IPage<BottomLink> getPage(Integer currentPage, Integer size, BottomLink bottomLink) {
        IPage<BottomLink> bottomLinkIPage = new Page<>(currentPage, size);
        LambdaQueryWrapper<BottomLink> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(BottomLink::getStatus,1);
        bottomLinkIPage = this.baseMapper.selectPage(bottomLinkIPage, queryWrapper);
        return bottomLinkIPage;
    }

    @Override
    public void add(BottomLink bottomLink) {
        bottomLink.setStatus(1);
        // 生成UUID并设置到实体对象中
        String uuid = UUID.randomUUID().toString();
        bottomLink.setLinkId(uuid);
        this.baseMapper.insert(bottomLink);
    }

    @Override
    public void edit(BottomLink bottomLink) {
        this.baseMapper.updateById(bottomLink);
    }

    @Override
    public void delete(BottomLink bottomLink) {
        bottomLink.setStatus(0);
        this.baseMapper.updateById(bottomLink);
    }
}
